//
// Created by v on 19-6-25.
//

#ifndef JKLIBS_CMDATABASEBASE_H
#define JKLIBS_CMDATABASEBASE_H

#include <iostream>
#include <list>
#include <map>
#include <vector>

/**
 * Name | Age | Area | Email |
 * Jone | 16 | china | xxx |
 * Siny | 28 | china | xxyy |
 *
 * like this
 * m_head will push Name, Age, Area, Email
 * m_result will push list of (Jone, 16, china, xxx), (Siny, 16, china, xxyy)
 * m_resultEx will save list with map<key, value>, so you can get value with
 * xxx[key] ex: m_resultEx[0][Name] is Jone, m_resultEx[0][Age] is 16
 *       m_resultEx[1][Name] is Siny, m_result[1][Email] is xxyy
 *
 * m_errMsg will give result if have error
 */
class CMDatabaseResult
{
  public:
    std::vector<std::string>              m_head;
    std::vector<std::vector<std::string>> m_result;

    std::vector<std::map<std::string, std::string>> m_resultEx;

    std::string m_errMsg;
};

class CMDatabaseBase
{
  public:
    explicit CMDatabaseBase(const char *dbfile);
    virtual ~CMDatabaseBase();

    virtual int dbConnect() = 0;

    virtual int dbDisconnect() = 0;

    virtual int dbQuery(const char *sql, CMDatabaseResult &result)       = 0;
    virtual int dbQueryResult(const char *sql, CMDatabaseResult &result) = 0;

  protected:
    std::string m_dbfile;
    bool        m_valid;
};

#endif // JKLIBS_CMDATABASEBASE_H
